//校验工具类
Validate = {
	isNull : function(value) {
		return (value ==  undefined  || value ==  "undefined" || value == null || value =="" || String.trim(value) == "")
	},
	validateBaseInfo : function(_packageBaseInfo) {
		var _flag = true;
		//校验必填内容是否填写
		//_packageBaseInfo = new PackageBaseInfo();
		if(Validate.isNull(_packageBaseInfo)) {
			PACK.ALERT.warn("请填写包基本信息！");
			_flag = false;
			return _flag;
		}
		if(Validate.isNull(_packageBaseInfo.getName())) {
			PACK.ALERT.warn("请填写包名称！");
			_flag = false;
			return _flag;
		}
		if(Validate.isNull(_packageBaseInfo.getPackageCode())) {
			PACK.ALERT.warn("请填写包编码！");
			_flag = false;
			return _flag;
		}
		if(Validate.isNull(_packageBaseInfo.getStartDate())) {
			PACK.ALERT.warn("请选择开始时间！");
			_flag = false;
			return _flag;
		}
		if(Validate.isNull(_packageBaseInfo.getEndDate())) {
			PACK.ALERT.warn("请选择结束时间！");
			_flag = false;
			return _flag;
		}
		if (_packageBaseInfo.getStartDate() >= _packageBaseInfo.getEndDate()) {
			PACK.ALERT.warn("【开始时间】不能大于或等于【结束时间】！");
			_flag = false;
			return _flag;
		}
		//包【结束时间】不能小于【当前时间】
		var sysDate = _packageBaseInfo.getEndDate().split('-');
		var myDate=new Date();
		myDate.setFullYear(sysDate[0],(sysDate[1]-1), sysDate[2]);
		var today = new Date();
		if (today > myDate){
			PACK.ALERT.warn("【结束时间】不能小于【当前时间】！");
			_flag = false;
			return _flag;
		}
		if(Validate.isNull(_packageBaseInfo.getDescription())) {
			PACK.ALERT.warn("请填写包描述！");
			_flag = false;
			return _flag;
		}
		//字数限制
		if(_packageBaseInfo.getName().length >30) {
			PACK.ALERT.warn("【包名称】不能大于30字符！");
			_flag = false;
			return _flag;
		}
		if(_packageBaseInfo.getPackageCode().length >20) {
			PACK.ALERT.warn("【包编码】不能大于20字符！");
			_flag = false;
			return _flag;
		}
		if(_packageBaseInfo.getReceiptContent() && (_packageBaseInfo.getReceiptContent().length >100)) {
			PACK.ALERT.warn("【包受理回执展示】不能大于100字符！");
			_flag = false;
			return _flag;
		}
		if(_packageBaseInfo.getDescription().length >100) {
			PACK.ALERT.warn("【包描述】不能大于100字符！");
			_flag = false;
			return _flag;
		}
		if(_packageBaseInfo.getPackageAD() && (_packageBaseInfo.getPackageAD().length >100)) {
			PACK.ALERT.warn("【包广告】不能大于100字符！");
			_flag = false;
			return _flag;
		}
		$.ajax({
				type:"POST",
				async: false,
				url:"../util/isPackCodeSingle.action",
				dataType:"json",
				data:{packCode:_packageBaseInfo.getPackageCode()},
				success:function(data){
					var _size = data.size;
					if (((operateType == PACKAGE.OPERATE.NEW) || (operateType == PACKAGE.OPERATE.COPYNEW)) 
							&& (_size != 0)) {
						PACK.ALERT.warn("包编码重复,请修改");
						_flag = false;
						return _flag;
					}
					if ((operateType == PACKAGE.OPERATE.MODIFY) && (_size > 1)) {
						PACK.ALERT.warn("包编码重复,请修改");
						_flag = false;
						return _flag;
					}
				}
			});
		
		return _flag;
	}
};
